# -* - coding: UTF-8 -* -
#import sys
#reload(sys)
#sys.setdefaultencoding('utf8')

import threading,string,subprocess
from time import sleep
from task import *
import logging
import json

class FirewallCommand(): 
		
	def block_ip(self,data,queue):
		
		if isinstance(data,str):
			logging.info('block_ip')
			logging.info(data)
			subprocess.call(['/sbin/iptables -I INPUT -s %s -j DROP' % data],  shell=True)
			subprocess.call(['service iptables save'], shell=True)
		elif isinstance(data,list):
			logging.info('block_ip')
			logging.info(data)
			for ip in data:
				subprocess.call(['/sbin/iptables -I INPUT -s %s -j DROP' % ip],  shell=True)
			subprocess.call(['service iptables save'], shell=True)
		return True		
		
